home *** CD-ROM | disk | FTP | other *** search
- unit Viewform;
- {$H-}
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Printers;
-
- type
- TCCForm = class(TForm)
- Memo1: TMemo;
- Panel1: TPanel;
- BitBtn1: TBitBtn;
- BitBtn2: TBitBtn;
- Edit1: TEdit;
- Label1: TLabel;
- Edit2: TEdit;
- Label2: TLabel;
- BitBtn3: TBitBtn;
- ComboBox1: TComboBox;
- Label3: TLabel;
- ComboBox2: TComboBox;
- Label4: TLabel;
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn2Click(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- private
- { Private declarations }
- procedure SetFileToShow(Value: string);
- public
- { Public declarations }
- property FileToShow: string write SetFileToShow;
- end;
-
- var
- CCForm: TCCForm;
-
- implementation
-
- {$R *.DFM}
-
- procedure TCCForm.SetFileToShow(Value: string);
- begin
- Memo1.Lines.Clear;
- Memo1.Lines.LoadFromFile(Value);
- end;
- procedure TCCForm.BitBtn1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TCCForm.BitBtn2Click(Sender: TObject);
- var
- F: TextFile;
- i: integer;
- begin
- { print memo.lines }
- Printer.Title := 'Form Print Demo';
- Printer.Canvas.Font.Name := ComboBox2.Text;
- Printer.Canvas.Font.Size := 10;
- AssignPrn(F);
- Rewrite(F);
- try
- for i := 0 to Memo1.Lines.Count-1 do
- Writeln(F, Memo1.Lines[i]);
- finally
- CloseFile(F);
- end;
- end;
-
- procedure TCCForm.FormShow(Sender: TObject);
- var
- i: LongInt;
- j: integer;
- F: TFileStream;
- Index: file of LongInt;
- S: string;
- begin
- { set screen elements }
- ComboBox1.Items.Assign(Screen.Fonts);
- ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(Memo1.Font.Name);
- ComboBox2.Items.Assign(Printer.Fonts);
- ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(Memo1.Font.Name);
- { assign and open index file }
- AssignFile(Index, ExtractFilePath(Application.ExeName)+'FILLSUM.NDX');
- Reset(Index);
- { open form file }
- F := TFileStream.Create(ExtractFilePath(Application.ExeName)+'FILLSUM.FRM', fmOpenWrite);
- try
- { iterate through index offsets }
- for j := 0 to FileSize(Index)-1 do
- begin
- Read(Index, i);
- { seek to offset }
- F.Seek(i, 0);
- case j of { case selector controls data output }
- { note: fields are formatted to fit designed
- field size - see article for alternate method }
- 0: S := Format('%-30s', [Edit1.Text]);
- 1: S := Format('%14s', [Edit2.Text]);
- 2: S := Format('%-10s', [DateToStr(Date)]);
- 3: S := Format('%-8s', ['N/A']);
- else S := Format('%10s', ['N/A']);
- end;
- { write data to stream }
- F.Write(S[1], Length(S));
- end;
- finally
- { clean up }
- F.Free;
- CloseFile(Index);
- end;
- { show file in memo }
- CCForm.FileToShow := ExtractFilePath(Application.ExeName)+'FILLSUM.FRM';
- end;
-
- procedure TCCForm.ComboBox1Change(Sender: TObject);
- begin
- Memo1.Font.Name := ComboBox1.Text;
- ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(Memo1.Font.Name);
- end;
-
- end.
-